import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";

// // 动态路由的引入
// import routerData from "@/utils/utils";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "Home",
    component: Home,
  },
];

// 添加路由
export function routerPageAdd(data) {
  let tempData = [];
  data.forEach((element) => {
    tempData.push({
      path: element.path,
      name: element.name,
      // route level code-splitting
      // this generates a separate chunk (about.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () =>
        import(/* webpackChunkName: "about" */ "../views/" + element.component),
    });
  });

  // 动态添加路由
  return router.addRoutes(tempData);
}

const router = new VueRouter({
  routes,
});

export default router;
